--------------------------------------------------------------------------
-- AltInvite.lua 
--------------------------------------------------------------------------
--[[
AltInvite

author: <zespri@mail.ru>

-Alt-click on a player name in chat to invite him/her in your group.

	$Id: AltInvite.lua 26 2010-10-16 03:43:33Z Kharthus1 $
	$Rev: 26 $
	$LastChangedBy: Kharthus1 $
	$Date: 2010-10-16 03:43:33 +0000 (Sat, 16 Oct 2010) $
]]

AltInvite_Enabled = true;

function AltInvite_SetItemRef (link)
	if ( strsub(link, 1, 6) == "player" ) and AltInvite_Enabled then
		local namelink = strsub(link, 8);
		local name, lineid = strsplit(":", namelink);
		if ( name and (strlen(name) > 0) ) then
			local begin = string.find(name, "%s[^%s]+$");
			if ( begin ) then
				name = strsub(name, begin+1);
			end
			if ( IsAltKeyDown() ) then
				InviteUnit(name);
				return false;
			end
		end
	end
	return true;
end

Sea.util.hook("SetItemRef", "AltInvite_SetItemRef", "hide");


function AltInvite_OnLoad()
	if (Khaos) then
		AltInvite_Register_Khaos();
	end
end

function AltInvite_Register_Khaos()
	local optionSet = {
		id="AltInvite";
		text=ALTINVITE_CONFIG_HEADER;
		helptext=ALTINVITE_CONFIG_HEADER_INFO;
		difficulty=1;
		default = false;
		callback = function(checked)
			AltInvite_Enabled = checked;
		end;
		feedback=function(state) return ALTINVITE_ENABLED_INFO; end;
		options={
			{
				id="Header";
				text=ALTINVITE_CONFIG_HEADER;
				helptext=ALTINVITE_CONFIG_HEADER_INFO;
				type=K_HEADER;
				difficulty=1;
			};
		};
	};
	Khaos.registerOptionSet(
		"chat",
		optionSet
	);
end
